<template>
  <home-nav-bar :islogin="islogin" :username="username" :nickname="nickname"></home-nav-bar>
  <home-main-content></home-main-content>

</template>

<script>
import axios from "axios";

import HomeNavBar from "@/index/components/HomeNavBar";
import HomeMainContent from "@/index/components/HomeMainContent";
import qs from "qs";

export default {
  name: "Home",
  data() {
    return {
      islogin: null,
      username: null,
      nickname: null,
    }
  },
  components: {
    HomeNavBar,
    HomeMainContent,
  },
  created() {

  },
  mounted() {
    this.getInfo()
    this.varifyLoginStatus()
  },
  methods: {
    // 检查登录状态
    varifyLoginStatus() {

      this.username = localStorage.getItem('id')
      console.log(this.username);
      if (this.islogin == null) {
        this.islogin = false
      }

      if (this.username == null) {
        this.islogin = false
        this.username = ''
      }
      else {
        this.islogin = true
      }
      console.log(this.islogin);
      console.log(this.username);
    },

    getInfo() {
      // this.id = localStorage.getItem('id')
      const data = {
        id: localStorage.getItem('id')
      }
      axios.post('/api/user/getInfo',qs.stringify(data)).then((res) => {
        if(res.data.code === 0) {
          this.nickname = res.data.data.username
          localStorage.setItem('nick',this.nickname)
          // this.email = res.data.data.email
        } else {
        }
      })
    }

  }
}
</script>

<style>

  .el-header {
    background-color: #B3C0D1;
    color: #333;
    line-height: 60px;
  }

</style>
